
<!-- 自定义纸张尺寸 -->
<template>
  <el-dialog
    :title="'自定义纸张尺寸'"
    :visible.sync="visible"
    width="500px"
    @close="handleClose"
  >
    <el-form ref="form" :model="customForm" :rules="rules" label-width="100px">
      <el-form-item label="纸张尺寸名称" prop="name">
        <el-input v-model="customForm.name" placeholder="请输入纸张尺寸名称" />
      </el-form-item>
      <el-form-item label="长度(mm)" prop="length">
        <el-input-number
          v-model="customForm.length"
          :min="1"
          placeholder="请输入长度"
        />
      </el-form-item>
      <el-form-item label="宽度(mm)" prop="width">
        <el-input-number
          v-model="customForm.width"
          :min="1"
          placeholder="请输入宽度"
        />
      </el-form-item>
    </el-form>

    <div slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="submitCustomSize">确定</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      customForm: {
        name: "",
        length: 297,
        width: 210,
      },
      rules: {
        name: [{ required: true, message: "请输入名称", trigger: "blur" }],
        length: [{ required: true, message: "请输入长度", trigger: "change" }],
        width: [{ required: true, message: "请输入宽度", trigger: "change" }],
      },
    };
  },
  methods: {
    submitCustomSize() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          // 发送数据给父组件
          this.$emit("confirm", { ...this.customForm }); // 使用展开运算符防引用问题

          this.$emit("update:visible", false);
        }
      });
    },
    resetForm() {
      this.$refs["form"].resetFields();
    },
    handleClose() {
      this.$emit("update:visible", false);
    },
  },
};
</script>